<?php namespace App\Http\Controllers\Site;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Item;
use Illuminate\Support\Facades\Cache;

class CompanyController extends Controller{
    public function __construct()
    {
        parent::__construct();
        view()->share('pageName','company');
    }

    public function getIndex($type = ""){
        $list = Item::where('type','company');
        if("" != $type){
            $list = $list->where('kind',$type);
        }
        $list = $list->paginate(config('site.pageSize'));
        $items = config('site.items.company');
        return view('site.company.index',[
            'companies'  => $list,
            'type'  => $type,
            'items' => $items
        ]);
    }

    public function getDetail($id = 0){
        $model = Item::find($id);
        if("" == $model || $model->type != "company"){
            abort(404);
        } else {
            return view('site.company.detail',[
                'model' => $model,
                'data'  => json_decode($model->content)
            ]);
        }
    }
}